class Solution:
    def largestAltitude(self, gain: List[int]) -> int:
        begin = 0
        ans = -inf
        for i in range(len(gain)):
            begin = begin + gain[i]
            ans = max(begin, ans)
        return ans if ans >= 0 else 0 # 出发点即最高点